package com.weiqiao.mall.rest;


import com.weiqiao.aop.log.Log;
import com.weiqiao.mall.domain.FreightEntity;
import com.weiqiao.mall.domain.ShopkeeperEntity;
import com.weiqiao.mall.service.*;
import com.weiqiao.mall.service.vo.AddressVO;
import com.weiqiao.mall.service.vo.CommodityTypeVO;
import com.weiqiao.mall.service.vo.CommodityVO;
import com.weiqiao.mall.service.vo.FreightVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 店铺管理控制层 StoreManagementController
 *
 * @author
 */
@RestController
@RequestMapping("/api")
public class StoreManagementController {

    /**
     * 货架管理业务层
     */
    @Autowired
    private IShopkeeperService shopkeeperBiz;


    @Autowired
    private IFreightService freightBiz;


    @Autowired
    private ICommodityLogService commodityLogService;

    @Autowired
    private IVarietyService varietyService;

    @Autowired
    private ICommodityListService commodityListService;

    @Log("商城配置")
    @PostMapping("/mall-list")
    public ResponseEntity mallList(@RequestBody AddressVO address) {
        return new ResponseEntity(shopkeeperBiz.getMallList(address), HttpStatus.OK);
    }

    @Log("运费模板列表")
    @PostMapping("/freight-list")
    public ResponseEntity freightList(@RequestBody AddressVO address) {
        return new ResponseEntity(freightBiz.getFreightList(address), HttpStatus.OK);
    }

    @Log("查看商品日志")
    @GetMapping("/commodity-log")
    public ResponseEntity commodityLog(CommodityVO commodityVO) {
        return new ResponseEntity(commodityLogService.getCommodityLogList(commodityVO), HttpStatus.OK);
    }

    @Log("商品分类列表")
    @GetMapping("/commodity-variety")
    public ResponseEntity commodityVariety(CommodityTypeVO commodityTypeVO) {
        return new ResponseEntity(varietyService.getList(commodityTypeVO), HttpStatus.OK);
    }

    @Log("删除商品分类")
    @PostMapping("delete-variety")
    public ResponseEntity deleteById(@RequestBody CommodityTypeVO commodityTypeVO) {
        return new ResponseEntity(commodityListService.deleteVariety(commodityTypeVO), HttpStatus.OK);
    }

    @Log("保存商品分类")
    @PostMapping("save-variety")
    public ResponseEntity saveVariety(@RequestBody CommodityTypeVO commodityTypeVO) {
        return new ResponseEntity(varietyService.saveVarietyList(commodityTypeVO), HttpStatus.OK);
    }

    @Log("店铺管理--修改")
    @PostMapping("/update-base-mall")
    public ResponseEntity updateBaseMall(@RequestBody ShopkeeperEntity shop) {
        return new ResponseEntity(shopkeeperBiz.updateShopByEntity(shop), HttpStatus.OK);
    }

    @Log("商城配置  添加地址  更新地址")
    @PostMapping("/update-address")
    public ResponseEntity updateAddress(@RequestBody AddressVO address) {
        return new ResponseEntity(shopkeeperBiz.updateAddress(address), HttpStatus.OK);
    }

    @Log("商城配置  删除地址")
    @PostMapping("/delete-address")
    public ResponseEntity deleteAddressById(@RequestBody AddressVO addressVO) {
        return new ResponseEntity(shopkeeperBiz.deleteAddress(addressVO), HttpStatus.OK);
    }

    @Log("商城配置 添加运费模板 更新运费模板")
    @PostMapping("/update-freight")
    public ResponseEntity updateFreight(@RequestBody FreightEntity freight) {
        return new ResponseEntity(freightBiz.updateFreightService(freight), HttpStatus.OK);
    }

    @Log("商城配置  运费模板删除")
    @PostMapping("/del-template")
    public ResponseEntity delTemplateById(@RequestBody FreightVO freightVO) {
        return new ResponseEntity(freightBiz.delFreight(freightVO), HttpStatus.OK);
    }
}
